<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Session;
class Index extends Controller
{
    // 管理员登录页
    public function index()
    {
        return $this->fetch();
    }
    //处理登录
    public function login()
    {
        $data = [
            "admin_phone"=>input('admin_phone'),
            "admin_pw"=>md5(input('admin_pw')),
        ];
        // dump($data);
        // exit;
        $res = Db::name('admin')->where($data)->find();
        // dump($res);
        // exit;
        if($res==null){
            return $this->error('账号密码错误');
        }else{
            Session::set("admin_id",$res["admin_id"]);
            $this->success('登录成功','company/index');
        }
    }
    //注销功能
    public function logout(){
        Session::clear();
        $this->redirect("index/index");
    }
}
